|
|
|
|
|
|
|
Throughout the preceding sections, you explored how to use the Microsoft Word Object Library. You used early binding, meaning that objects are declared as a specific type rather than the more generic Object data type. However, if you have to maintain older Visual Basic applications, you may find a different library, the WordBasic library. Applications that use this object generally declare them as late bound, as in the following example: |
|
|
|
|
|
|
|
|
Dim objWord As Object
Set objWord = CreateObject("Word.Basic") |
|
|
|
|
|
|
|
|
The commands also differ slightly: |
|
|
|
|
|
|
|
|
objWord.FileNew
objWord.StartOfDocument
objWord.FontSize 24
objWord.Insert "Some Big Text"
objWord.FontSize 12
objWord.InsertPara
objWord.Insert "Some Smaller Text"
objWord.FileSaveAS "C:\TEST.DOC"
Set objWord = Nothing |
|
|
|
|
|
|
|
|
Using the preceding example is definitely not the preferred way to access Word from VB, but it is mentioned here so that you are not confused if you run into some old code. |
|
|
|
|
|
|
|
|
You can also control Excel from your Visual Basic applications by using the same techniques that you use with Microsoft Word. Like Word, Excel has its own object library, which must be referenced in your Visual Basic project. By using OLE automation with Excel, you can create some neat-looking reports, such as the one shown in Figure 22.3. The layout and formatting of the report was created in Excel, and Visual Basic was used to supply the data. |
|
|
|
|
|
|
|
|
Figure 22.3
This report, which includes a graph and several
columns of numbers, would be very difficult to
create with Visual Basic's built-in printing functions. |
|
|
|
|
|